package com.pengtu.entity.business.detection;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Attachment;

/**
 * 交工验收审查情况及存在问题
 * 
 * @author liuyang
 * 
 */
@Entity
@Table(name = "T_Q_CASE_DETN_ISSUE")
public class DetnIssue extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String projId; // 工程
	private DetnReport detnReport; // 检测
	private String type; // 问题类型
	private String content; // 概要描述
	private String contentFile; // 附件

	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			});

	private String dealContent; // 处理措施
	private Date dealDate; // 处理时间
	private String remark; // 备注

	@Column(name = "PID")
	public String getProjId() {
		return projId;
	}

	public void setProjId(String projId) {
		this.projId = projId;
	}

	@ManyToOne(targetEntity = DetnReport.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "CID")
	public DetnReport getDetnReport() {
		return detnReport;
	}

	public void setDetnReport(DetnReport detnReport) {
		this.detnReport = detnReport;
	}

	@Column(name = "TYPE")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "CONTENT")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "CONTENTFILE")
	public String getContentFile() {
		return contentFile;
	}

	public void setContentFile(String contentFile) {
		this.contentFile = contentFile;
	}

	@Column(name = "DEALCONTENT")
	public String getDealContent() {
		return dealContent;
	}

	public void setDealContent(String dealContent) {
		this.dealContent = dealContent;
	}

	@Column(name = "DEALDATE")
	public Date getDealDate() {
		return dealDate;
	}

	public void setDealDate(Date dealDate) {
		this.dealDate = dealDate;
	}

	@Column(name = "REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}

	public void setAttachmentSet(Set<Attachment> attachmentSet) {
		this.attachmentSet = attachmentSet;
	}

	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}
}
